package org.dlsu.mt.parser.dictionary;

/**
 * made by LEFT thesis group
 *
 * monolingual dictionary module
 *
 * VerbClass class extends WordClass
 * extends the WordClass class in order to add functions to better represent verbs
 */


public class VerbClass extends WordClass
{
	private FunctionList functions; //contains a list of functions that apply to the verb
	
	public VerbClass(String id)
	{
		/**
		 * constructor with no parameters
		 * instantiates the object by giving the value "verb" as the part of speech
		 */
		super(id, "verb");
		functions = new FunctionList();
	}
	
	public VerbClass(String id, List semantics,CollocationList collocation)
	{
		/**
		 * constructor that takes as parameter a list of semantics and collocations
		 * instantiates the object by copying the lists passed as parameter to the object
		 */
		super(id, "verb", semantics, collocation);
		functions = new FunctionList();
	}
	
	public VerbClass(String id, List semantics, CollocationList collocation, FunctionList functions)
	{
		/**
		 * constructor that takes as parameter a list of semantics, collocations and functions
		 * instantiates the object by copying the lists as passed as parameter to the object
		 */
		super(id, "verb", semantics, collocation);
		this.functions = functions;
	}
	
	public Function getNextFunction()
	{
		/**
		 * gets the next element in the function list, activates the iterator if it is inactive, resets it to the
		 * beginning of the iteration if it has reached the end of the list
		 */
		if(functions.iterationActive())
		{
			if(!functions.hasMoreElements())
			{
				functions.resetIterator();
			}
			return functions.nextElement();
		}
		else
		{
			functions.resetIterator();
			return functions.nextElement();
		}
	}
	
	public boolean addFunction(String entry)
	{
		/**
		 * adds a function to the function list by passing it as a single string
		 * returns true if add is successful
		 * returns false otherwise
		 */
		return functions.addElement(entry);
	}
	
	public boolean removefunction(String entry)
	{
		/**
		 * removes a function from the list of functions
		 * returns true if remove is successful
		 * returns false otherwise
		 */
		return functions.removeElement(entry);
	}
	
	public void mergeWordClass(WordClass w)
	{
		/**
		 * merges the word class passed in the parameter with this word class
		 * copies all semantic information, collocation, and functions
		 */
		super.mergeWordClass(w);
		if(w.getPOS().equals("verb"))
		{
			VerbClass v = (VerbClass)w;
			String first = v.getNextFunction().getSymbols();
			String temp = null;
			if(first!=null)
			{
				do
				{
					if(temp == null)
						temp = first;
					else
					{
						addFunction(temp);
						temp = v.getNextFunction().getSymbols();
					}
				}while(!temp.equals(first));
			}
		}
	}
}